<!DOCTYPE html>
<html>
<head>
	<title>校园破冰交友与失物招领平台-登录</title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<link rel="stylesheet" type="text/css" href="../assets/css/login.css"/>
	<link rel="stylesheet" type="text/css" href="../assets/css/bootstrap.min.css"/>
</head>
<body>
<div class="agileits-main">
	<div class="header-main">
		<h2>校园破冰交友与失物招领平台</h2>
		<div class="header-bottom">
			<div class="header-right w3agile">
				<div class="header-left-bottom agileinfo">
					<form>
						<div class="icon1">
							<input type="text" placeholder="用户名" id="username" value="2018b31036"/>
						</div>
						<div class="icon1">
							<input type="password" placeholder="密码" id="password" value="000000"/>
						</div>
						<div class="login-check">
							 <label class="radio">
								<input type="radio" name="role" value="0" checked>学生
								<input type="radio" name="role" value="1">老师
								<input type="radio" name="role" value="2">管理员
							</label>
						</div>
						<div class="bottom">
							<input type="button" value="登录" id="loginButton"/>
						</div>
						<p><a href="register.html">注册</a></p>
						<p><a href="#">忘记密码?</a></p>
					</form>	
				</div>
			</div>
		</div>
	</div>
</div>
<div class="copyright w3-agile">
	<p>Copyright © 2019 黄胜瑾</p>
</div>
<script src="../assets/js/jquery-min.js"></script>
<script src="../assets/js/bootstrap.min.js"></script>
<script src="../assets/js/main.js"></script>
<script src="../assets/js/jquery.bootstrap-growl.js"></script>
<script>
    $(function () {
        $("#loginButton").click(function () {
            $.ajax({
                type: "post",
                url: ctx+"/user/login",
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                data: {username:$("#username").val(),password:$("#password").val(),role:$("[name='role']:checked").val()},
                success: function (data) {
                    if(data.username!=null){
                    	if(data.id==null){
							$.bootstrapGrowl("对不起，您被封号至"+data.sealTime);
						}else{
							sessionStorage.setItem("user", JSON.stringify(data));
							window.location.href="../index/index.html";
						}
                    }else{
                        $.bootstrapGrowl("账号或密码错误");
                    }
                },
                error: function () {
                    $.bootstrapGrowl("登录请求失败");
                }
            })
        })
    })
</script>
</body>
</html>